setwd ("C:/pyrogeography/FIRESCARASCII/outdir/")
test = read.csv ("firebkgd1km.txt")
names(test) = c("FID", "point", "grid", "LONGDEC", "LATDEC")
test$FID = NULL; test$point = NULL; test$point = NULL ; test$grid = NULL
test[1:10,]
dim (test)
test$xround = round(test$LONGDEC/ 0.05)* 0.05
test$yround = round(test$LATDEC / 0.05)* 0.05

bckgd_rnd_5km = data.frame(test$yround, test$xround)
names (bckgd_rnd_5km) = c("LATDEC", "LONGDEC")

bgnd = unique (bckgd_rnd_5km)
dim (bckgd_rnd_5km)
bckgd_rnd_5km [1:10,]
dim(bgnd)


#### create the unique background for each year month combination

outdir = "C:/pyrogeography/FIRESCARASCII/outdir/background_data/"
year = 2000:2009
month = 1:12
month = sprintf('%02d',month)

for (yy in year){
        for (mm in month) {
            bgnd$year = yy
            bgnd$month = mm
            bgnd$tfile = paste(bgnd$year, bgnd$month, sep = "")
       write.csv (bgnd,(paste(outdir, yy, mm, ".csv", sep = "")))
      }
      }

# read in all the .csv files and combine them for a representative background

cd /home1/55/jc224266/working/fire/fireasc/firebackground

outdir = "/home1/55/jc224266/working/fire/fireasc/firebackground/"

bkgdfiles = list.files(outdir)
print (bkgdfiles)

for (blah in bkgdfiles){
	if (file.exists(paste(outdir,blah,sep=''))) {
		cat(blah,'\n')  }
		#read in the csv.data files and append
		date = c()
    for (x in c(paste(outdir, bkgdfiles, sep=''))) {
      u<-read.csv(x)
      u$dataset = x
      date <- rbind(date, u)
      }
      }

 date[1:10,]
 

